package com.business.web.spring;


import java.util.List;
import org.apache.log4j.Logger;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.business.domain.T_task_node_instance;
import com.easyworkflow.web.spring.WorkFlowController;

//import com.workflow.WorkFlowUtils;
import com.common.db.JsonVO;
import com.common.db.Pg;
import com.common.utils.BeanUtils;
import com.business.domain.T_building;
//import com.business.mapper.T_buildingMapper;
import com.business.service.T_buildingService;

@Controller
@RequestMapping("/t_building")

public class T_buildingController extends WorkFlowController{

	private static Logger log = Logger.getLogger(T_buildingController.class.getName());

	@Resource
    private T_buildingService t_buildingService;

	//@Autowired
	//private WorkFlowUtils workFlowUtils;

	//@Resource
	//private T_buildingMapper mapper;
	//private int id;
	//private int[] ids;
	private Pg pg;

	/**
	 * 1、获取 T_building信息列表，并且在列表页面展示
	 * @param request
	 * @return Pg，json格式
	 */
	@RequestMapping("/getAllT_building")
	@ResponseBody
	public Pg getAllT_building(HttpServletRequest request){
        int pageSize = 10;
        int startIndex = 0;
        T_building t_building = new T_building();
        try{
	        if(request.getParameter("pageSize")!=null){
	        	pageSize = BeanUtils.stringToInt("pageSizeFlag", request.getParameter("pageSize"));
	        }
	        if(request.getParameter("startIndex")!=null){
	            startIndex = BeanUtils.stringToInt("startIndexFlag", request.getParameter("startIndex"));
	        }
	        if(request.getParameter("process_code")!=null){ //取得动作流 流程英文名称，后台查询数据关联使用
	        	t_building.setProcess_code(request.getParameter("process_code"));
	        }
			if(request.getParameter("name")!=null&&!"".equals(request.getParameter("name"))){
	        	t_building.setName(request.getParameter("name"));
	        }
			if(request.getParameter("useofbuilding")!=null&&!"".equals(request.getParameter("useofbuilding"))){
	        	t_building.setUseofbuilding(request.getParameter("useofbuilding"));
	        }
			if(request.getParameter("linkman")!=null&&!"".equals(request.getParameter("linkman"))){
	        	t_building.setLinkman(request.getParameter("linkman"));
	        }
			if(request.getParameter("linktel")!=null&&!"".equals(request.getParameter("linktel"))){
	        	t_building.setLinktel(request.getParameter("linktel"));
	        }
			if(request.getParameter("ext1")!=null&&!"".equals(request.getParameter("ext1"))){
	        	t_building.setExt1(request.getParameter("ext1"));
	        }
			if(request.getParameter("ext2")!=null&&!"".equals(request.getParameter("ext2"))){
	        	t_building.setExt2(request.getParameter("ext2"));
	        }
			if(request.getParameter("ext3")!=null&&!"".equals(request.getParameter("ext3"))){
	        	t_building.setExt3(request.getParameter("ext3"));
	        }
			if(request.getParameter("ext4")!=null&&!"".equals(request.getParameter("ext4"))){
	        	t_building.setExt4(request.getParameter("ext4"));
	        }
			if(request.getParameter("ext5")!=null&&!"".equals(request.getParameter("ext5"))){
	        	t_building.setExt5(request.getParameter("ext5"));
	        }
			if(request.getParameter("ext6")!=null&&!"".equals(request.getParameter("ext6"))){
	        	t_building.setExt6(request.getParameter("ext6"));
	        }
			if(request.getParameter("creater")!=null&&!"".equals(request.getParameter("creater"))){
	        	t_building.setCreater(request.getParameter("creater"));
	        }
			if(request.getParameter("creattime")!=null&&!"".equals(request.getParameter("creattime"))){
	        	t_building.setCreattime(request.getParameter("creattime"));
	        }
			if(request.getParameter("updater")!=null&&!"".equals(request.getParameter("updater"))){
	        	t_building.setUpdater(request.getParameter("updater"));
	        }
			if(request.getParameter("updatetime")!=null&&!"".equals(request.getParameter("updatetime"))){
	        	t_building.setUpdatetime(request.getParameter("updatetime"));
	        }
			if(request.getParameter("biztype")!=null&&!"".equals(request.getParameter("biztype"))){
	        	t_building.setBiztype(request.getParameter("biztype"));
	        }
			if(request.getParameter("publicrate")!=null&&!"".equals(request.getParameter("publicrate"))){
	        	t_building.setPublicrate(request.getParameter("publicrate"));
	        }
			if(request.getParameter("imgpath")!=null&&!"".equals(request.getParameter("imgpath"))){
	        	t_building.setImgpath(request.getParameter("imgpath"));
	        }
			if(request.getParameter("note")!=null&&!"".equals(request.getParameter("note"))){
	        	t_building.setNote(request.getParameter("note"));
	        }
			if(request.getParameter("memo")!=null&&!"".equals(request.getParameter("memo"))){
	        	t_building.setMemo(request.getParameter("memo"));
	        }
			if(request.getParameter("attach")!=null&&!"".equals(request.getParameter("attach"))){
	        	t_building.setAttach(request.getParameter("attach"));
	        }
			if(request.getParameter("htyajinunit")!=null&&!"".equals(request.getParameter("htyajinunit"))){
	        	t_building.setHtyajinunit(request.getParameter("htyajinunit"));
	        }
			if(request.getParameter("feiyongname")!=null&&!"".equals(request.getParameter("feiyongname"))){
	        	t_building.setFeiyongname(request.getParameter("feiyongname"));
	        }
			if(request.getParameter("huowumingcheng")!=null&&!"".equals(request.getParameter("huowumingcheng"))){
	        	t_building.setHuowumingcheng(request.getParameter("huowumingcheng"));
	        }
			if(request.getParameter("youhuizhengce")!=null&&!"".equals(request.getParameter("youhuizhengce"))){
	        	t_building.setYouhuizhengce(request.getParameter("youhuizhengce"));
	        }
			if(request.getParameter("youhuizhengcename")!=null&&!"".equals(request.getParameter("youhuizhengcename"))){
	        	t_building.setYouhuizhengcename(request.getParameter("youhuizhengcename"));
	        }
			if(request.getParameter("buildingtype")!=null&&!"".equals(request.getParameter("buildingtype"))){
	        	t_building.setBuildingtype(request.getParameter("buildingtype"));
	        }
			if(request.getParameter("contractfeeunit")!=null&&!"".equals(request.getParameter("contractfeeunit"))){
	        	t_building.setContractfeeunit(request.getParameter("contractfeeunit"));
	        }
			if(request.getParameter("contractnumunit")!=null&&!"".equals(request.getParameter("contractnumunit"))){
	        	t_building.setContractnumunit(request.getParameter("contractnumunit"));
	        }
			if(request.getParameter("contractcounttype")!=null&&!"".equals(request.getParameter("contractcounttype"))){
	        	t_building.setContractcounttype(request.getParameter("contractcounttype"));
	        }
			if(request.getParameter("contractpaytype")!=null&&!"".equals(request.getParameter("contractpaytype"))){
	        	t_building.setContractpaytype(request.getParameter("contractpaytype"));
	        }
			if(request.getParameter("contractdatetype")!=null&&!"".equals(request.getParameter("contractdatetype"))){
	        	t_building.setContractdatetype(request.getParameter("contractdatetype"));
	        }
			if(request.getParameter("energyfeeunit")!=null&&!"".equals(request.getParameter("energyfeeunit"))){
	        	t_building.setEnergyfeeunit(request.getParameter("energyfeeunit"));
	        }
			if(request.getParameter("energytnumunit")!=null&&!"".equals(request.getParameter("energytnumunit"))){
	        	t_building.setEnergytnumunit(request.getParameter("energytnumunit"));
	        }
			if(request.getParameter("energycounttype")!=null&&!"".equals(request.getParameter("energycounttype"))){
	        	t_building.setEnergycounttype(request.getParameter("energycounttype"));
	        }
			if(request.getParameter("energypaytype")!=null&&!"".equals(request.getParameter("energypaytype"))){
	        	t_building.setEnergypaytype(request.getParameter("energypaytype"));
	        }
			if(request.getParameter("energytdatetype")!=null&&!"".equals(request.getParameter("energytdatetype"))){
	        	t_building.setEnergytdatetype(request.getParameter("energytdatetype"));
	        }
			if(request.getParameter("propertyfeeunit")!=null&&!"".equals(request.getParameter("propertyfeeunit"))){
	        	t_building.setPropertyfeeunit(request.getParameter("propertyfeeunit"));
	        }
			if(request.getParameter("propertynumunit")!=null&&!"".equals(request.getParameter("propertynumunit"))){
	        	t_building.setPropertynumunit(request.getParameter("propertynumunit"));
	        }
			if(request.getParameter("propertycounttype")!=null&&!"".equals(request.getParameter("propertycounttype"))){
	        	t_building.setPropertycounttype(request.getParameter("propertycounttype"));
	        }
			if(request.getParameter("propertypaytype")!=null&&!"".equals(request.getParameter("propertypaytype"))){
	        	t_building.setPropertypaytype(request.getParameter("propertypaytype"));
	        }
			if(request.getParameter("propertydatetype")!=null&&!"".equals(request.getParameter("propertydatetype"))){
	        	t_building.setPropertydatetype(request.getParameter("propertydatetype"));
	        }
			if(request.getParameter("ext7")!=null&&!"".equals(request.getParameter("ext7"))){
	        	t_building.setExt7(request.getParameter("ext7"));
	        }
			if(request.getParameter("ext8")!=null&&!"".equals(request.getParameter("ext8"))){
	        	t_building.setExt8(request.getParameter("ext8"));
	        }
			if(request.getParameter("ext9")!=null&&!"".equals(request.getParameter("ext9"))){
	        	t_building.setExt9(request.getParameter("ext9"));
	        }
			if(request.getParameter("ext10")!=null&&!"".equals(request.getParameter("ext10"))){
	        	t_building.setExt10(request.getParameter("ext10"));
	        }
			if(request.getParameter("ext11")!=null&&!"".equals(request.getParameter("ext11"))){
	        	t_building.setExt11(request.getParameter("ext11"));
	        }
			if(request.getParameter("ext12")!=null&&!"".equals(request.getParameter("ext12"))){
	        	t_building.setExt12(request.getParameter("ext12"));
	        }
      	    if(request.getParameter("buildingid")!=null&&!"".equals(request.getParameter("buildingid"))){
	        	t_building.setBuildingid(new Integer(request.getParameter("buildingid")));
	        }

	        if(request.getParameter("startdate")!=null&&!"".equals(request.getParameter("startdate"))){
	        	t_building.setStartdate(request.getParameter("startdate"));
	        }
	        if(request.getParameter("enddate")!=null&&!"".equals(request.getParameter("enddate"))){
	        	t_building.setEnddate(request.getParameter("enddate"));
	        }
	        t_building.setStartNo( startIndex );
	        t_building.setPageSize( pageSize );
	        t_building.setEndNo( pageSize );
	    	List<T_building> findAll = t_buildingService.findAll(t_building);
	        int totalCount = t_buildingService.findCountAll(t_building);
	       	pg = new Pg(findAll, totalCount, pageSize, startIndex);
	       	request.setAttribute("t_buildingList", findAll);
		    request.setAttribute("pg", pg);
	    } catch (Exception e) {
			e.printStackTrace();
			log.error("------query t_buildingList error:"+e);
		}

		return pg;
	}

	/**
	 * 2、新增保存  T_building信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param t_building
	 * @param request
	 * @return
	 */
	@RequestMapping("/saveT_building")
	@ResponseBody
	public JsonVO saveT_building(T_building t_building, HttpServletRequest request,HttpServletResponse response){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊需求，需要将json对象值转成java实体对象属性值
		if(t_buildingService.save(t_building)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 3。1、修改T_building信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param t_building
	 * @param request
	 * @return JsonVO
	 */
	@RequestMapping("/updateT_building")
	@ResponseBody
	public JsonVO updateT_building(T_building t_building, HttpServletRequest request){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊值需要处理，在此处手工转换
		//T_building t_buildingTemp = t_buildingService.findById(t_building);
		//t_buildingTemp.setXXX(t_building.getXXX());
		//if(t_buildingService.update(t_buildingTemp)){

		if(t_buildingService.update(t_building)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

    /**
     * 3。2、提交审核业务数据
     * 修改T_building信息并且返回成功或者失败信息json格式结果如：result:[success/error]
     * @param t_building
     * @param request
     * @return JsonVO
     */
    @RequestMapping("/tjshT_building")
    @ResponseBody
    public JsonVO tjshT_company(T_building t_building, HttpServletRequest request) {
        //启动工作流； 请假流程；
        return startMyTask( getTaskIdByBiztype(t_building.getBiztype()),t_building.getBiztype(), t_building.getBuildingid(), request);
    }

    /**
     * 3.3、提交T_building审核通过，并且返回成功或者失败信息json格式结果如：result:[success/error]
     * @param t_task_node_instance
     * @param request
     * @return JsonVO
     */
    @RequestMapping("/shtgT_building")
    @ResponseBody
    public JsonVO shtgT_building(T_task_node_instance t_task_node_instance, HttpServletRequest request) {
        return doMyAgree(t_task_node_instance.getTninstanceid(), t_task_node_instance.getNote(), request);
    }

    /**
     * 3.4、提交T_building审核退回，信息并且返回成功或者失败信息json格式结果如：result:[success/error]
     * @param t_task_node_instance
     * @param request
     * @return JsonVO
     */
    @RequestMapping("/shthT_building")
    @ResponseBody
    public JsonVO shthT_building(T_task_node_instance t_task_node_instance, HttpServletRequest request) {
        return doMyBack(t_task_node_instance.getTninstanceid(), t_task_node_instance.getNote(), request);
    }
    
	/**
	 * 4、根据id查询T_building单个信息并显示在修改页面
	 * @param id
	 * @param request
	 * @return T_building json格式字符串
	 */
	@RequestMapping("/getT_building")
	@ResponseBody
	public T_building getT_building(Integer id,HttpServletRequest request){
		T_building t_building = new T_building();
		t_building.setBuildingid(id);
		return t_buildingService.findById(t_building);
	}

	@RequestMapping("/delT_buildingAllFile")
	@ResponseBody
	public JsonVO delT_buildingAllFile(Integer id,HttpServletRequest request,HttpServletResponse response){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);

		T_building t_building = new T_building();
		t_building.setBuildingid(id);
		t_building = t_buildingService.findById(t_building);
		t_building.setImgpath("");
		t_building.setExt9("");

		t_building.setAttach("");

		if(t_buildingService.update(t_building)>0){
			vo.setResult("success");
			vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 5、删除T_building根据id
	 * @param id
	 * @param request
	 * @param response
	 * return JsonVO ：json格式字符串
	 */
	@RequestMapping("/delT_building")
	@ResponseBody
	public JsonVO delT_building(Integer id,HttpServletRequest request,HttpServletResponse response){
        JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);

		T_building t_building = new T_building();
		t_building.setBuildingid(id);

		if(t_buildingService.delete(t_building)>0){
			vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 6、跳转到t_building/toT_buildingList查询所有数据页面
	 *  return /WEB-INF/views/business/t_building/t_buildingList.jsp
	 */
    @RequestMapping(value = "/toT_buildingList")
    public String toT_buildingList() {
    	log.debug("------跳转到/WEB-INF/views/business/t_building/t_buildingList.jsp------");
        return "business/t_building/t_buildingList";
    }

	/**
	 * 7、新增、修改、详情页面t_building/toT_buildingCurd跳转
     * business/t_building/T_buildingCurd.jsp
	 */
    @RequestMapping(value = "/toT_buildingCurd")
    public String toT_buildingCurd() {
    	log.debug("------跳转到/WEB-INF/views/business/t_building/t_buildingCurd.jsp------");
        return "business/t_building/t_buildingCurd";
    }

    /**
	 * 8、批量删除T_building根据主键id
	 * 是否要实现批量删除，待考虑，基本上用途不大
	 * @param id
	 * @param request
	 * @param response
	@RequestMapping("/delT_buildingBatch")
	public String delT_buildingBatch(HttpServletRequest request,HttpServletResponse response){
		String[] ids = request.getParameterValues("ids");
		System.out.println("------ids="+ids);
		T_building t_building = new T_building();
		int j=0;
		for(int i =0;i< ids.length;i++){
			j++;
			log.error("------ids[i]="+ids[i]);
			t_building.setBuildingid(new Integer(ids[i]).intValue());
			t_buildingService.delete(t_building);
		}
		if(j==ids.length){
			log.debug("------t_building批量删除成功！------");
		}else{
			log.error("------t_building批量删除部分成功！部分失败！------");
		}

		return "redirect:/t_building/getAllT_building";
	}
*/



}









